import { defaultRequest as rq } from "./request";
import type { R } from "./request";

export interface Machine {
  machineId: string | undefined
  appName: string
  frameworks: []
  appVersion: string
  envName: string
  hostName: string
  ipPort: string
  startTime: string
  lastHeartbeatTime: string
  runTime: string
  status: string
}

export const guardcatInfoApi = (params?: object): Promise<R<any>> => {
  return rq.get<R<any>>("${GATEWAY_URL}/backend-bsms/guardcat/config", { params });
};

export const monitorAppsApi = (params?: object): Promise<R<any>> => {
  return rq.get<R<any>>("${GATEWAY_URL}/backend-bsms/guardcat/apps", { params });
};

/**
 * 获取应用和机器的树状列表
 * @param params 
 * @returns 
 */
export const monitorAppsTreeApi = (params?: object): Promise<R<any>> => {
  return rq.get<R<any>>("${GATEWAY_URL}/backend-bsms/guardcat/apps/tree", { params });
};

export const getMachineApi = (params?: object): Promise<R<any>> => {
  return rq.get<R<any>>("${GATEWAY_URL}/backend-bsms/guardcat/machine", { params });
};

export const deleteMachineApi = (params?: object): Promise<R<any>> => {
  return rq.delete<R<any>>("${GATEWAY_URL}/backend-bsms/guardcat/machine", { params });
};

export const getSettingApi = (params?: object): Promise<R<any>> => {
  return rq.get<R<any>>("${GATEWAY_URL}/backend-bsms/guardcat/server/alert/setting", { params });
};

export const saveSettingApi = (data?: object): Promise<R<any>> => {
  return rq.post<R<any>>("${GATEWAY_URL}/backend-bsms/guardcat/server/alert/setting", data);
};

// ---------------------------------------< JVM >---------------------------------------

export const jvmMemoryApi = (params?: object): Promise<R<any>> => {
  return rq.get<R<any>>("${GATEWAY_URL}/backend-bsms/guardcat/jmm", { params });
};

export const getPhysicalApi = (params?: object): Promise<R<any>> => {
  return rq.get<R<any>>("${GATEWAY_URL}/backend-bsms/guardcat/physical", { params });
};

export const getMemoryLineApi = (params?: object): Promise<R<any>> => {
  return rq.get<R<any>>("${GATEWAY_URL}/backend-bsms/guardcat/jmm/echart/line", { params });
};

export const getGcLineApi = (params?: object): Promise<R<any>> => {
  return rq.get<R<any>>("${GATEWAY_URL}/backend-bsms/guardcat/gc/echart/line", { params });
};

export const getGcApi = (params?: object): Promise<R<any>> => {
  return rq.get<R<any>>("${GATEWAY_URL}/backend-bsms/guardcat/gc", { params });
};

export const getThreadLineApi = (params?: object): Promise<R<any>> => {
  return rq.get<R<any>>("${GATEWAY_URL}/backend-bsms/guardcat/thread/echart/line", { params });
};